# Create your views here.
from django.shortcuts import render_to_response
from django.template.context import RequestContext
from django.http import HttpResponseRedirect
from python_residencia_rise.residenteApp.models import Residente
from python_residencia_rise.residenteApp.forms import ResidenteForm

def listar_residentes(request):
    residentes = Residente.objects.all()
        
    return render_to_response( 'listar_residentes.html', locals(), context_instance=RequestContext(request))
    

def novo_residente(request):
    
    if request.method == 'POST':
        form = ResidenteForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('listar')
    else:
        form = ResidenteForm()
    return render_to_response('novo_residente.html', locals(), context_instance=RequestContext(request))

    
def exibir_residente(request, id):
    residente = Residente.objects.get(pk=id)
    return render_to_response('exibir_residente.html', locals(), context_instance=RequestContext(request))
    
    
def apagar_residente(request, id):
    residente = Residente.objects.get(pk=id)
    residente.delete()
    return HttpResponseRedirect('listar')
    
    
def editar_residente(request):
    teste = 1
    
    
    
